#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

struct ListNode 
{
   int val;
   struct ListNode* next;
    
};

struct ListNode* reverseList(struct ListNode* head)
{
    if (head == NULL || head->next == NULL)
        return head;
    struct ListNode* p1, * p2, * p3;
    p1 = NULL;
    p2 = head;
    p3 = head->next;
    while (p2)
    {
        p2->next = p1;
        p1 = p2;
        p2 = p3;
        if (p3)
            p3 = p3->next;
    }
    return p1;
}